package com.hexgon.plugins.rabbitmq;

import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * 多RabbitMQ源的RabbitAdmin
 * @author: XuZhibin
 * @date: 2023/11/12 15:30
 * @version: v1.0
 * @attention:
 */
@Component
public class MultiRabbitAdmin {

    @Autowired
    private DefaultListableBeanFactory defaultListableBeanFactory;

    /**
     * 根据名称获取 RabbitAdmin
     * @param rabbitAdminName
     * @return
     */
    public RabbitAdmin adminInstance(String rabbitAdminName) {
        String beanName = rabbitAdminName + "RabbitAdmin";
        boolean existTemplate = defaultListableBeanFactory.containsBean(beanName);
        if (!existTemplate) {
            throw new IllegalArgumentException("无效的RabbitAdmin名称");
        }
        return defaultListableBeanFactory.getBean(beanName, RabbitAdmin.class);
    }
}
